//
//  XDOrganizationCell.m
//  XDEducation
//
//  Created by apple on 2017/4/25.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDOrganizationCell.h"
#import "XDOrganizationModel.h"
#import "XDExpericeModel.h"
@interface XDOrganizationCell()

@property (weak, nonatomic) IBOutlet UILabel *orgNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *telephoneLabel;

//加入butotn
@property (weak, nonatomic) IBOutlet UIButton *joinBtn;
//设为默认
@property (weak, nonatomic) IBOutlet UIButton *settingBtn;

//若页面为体验馆
//须要更改下面三个控件的名字
@property (weak, nonatomic) IBOutlet UILabel *orgTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *telephoneImageView;
@property (weak, nonatomic) IBOutlet UILabel *telephoneTitleLabel;

@end

@implementation XDOrganizationCell
{
    BOOL jionBtnClickedEnable; //判断是否可点击
}


//辅助机构设置数据
-(void)setOrgModel:(XDOrganizationModel *)orgModel{
    
    _orgModel = orgModel;
    
    _orgNameLabel.text = orgModel.orgName;
    
    _addressLabel.text = orgModel.orgAddress;
    
    _telephoneLabel.text = orgModel.orgTelephone;
    
    if ([orgModel.joined boolValue]) {
        [_joinBtn setTitle:@"已加入" forState:UIControlStateNormal];
        jionBtnClickedEnable = NO;
    }else{
        [_joinBtn setTitle:@"加入" forState:UIControlStateNormal];
        jionBtnClickedEnable = YES;
        [_joinBtn addTarget:self action:@selector(joinBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
}


//体验馆设置数据
-(void)setExpericeModel:(XDExpericeModel *)expericeModel{

    _expericeModel = expericeModel;
    
    _orgNameLabel.text = expericeModel.expericeName;
    
    _addressLabel.text = expericeModel.address;
    
    _telephoneLabel.text = expericeModel.introduce;
    
    if ([expericeModel.isJoined boolValue]) {
        [_joinBtn setTitle:@"已加入" forState:UIControlStateNormal];
        jionBtnClickedEnable = NO;
    }else{
        [_joinBtn setTitle:@"加入" forState:UIControlStateNormal];
        jionBtnClickedEnable = YES;
        [_joinBtn addTarget:self action:@selector(joinBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    
}


//判断cell类型
-(void)setCellType:(CellType)cellType{
    
    _cellType = cellType;
    
    if (cellType == CellTypeMyOrg || _cellType == CellTypeMyExperience) {
        
        _settingBtn.hidden = NO;
        [_settingBtn addTarget:self action:@selector(settingBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        [_joinBtn setTitle:@"取消加入" forState:UIControlStateNormal];
        
    }
    
    if (cellType == CellTypeExperience) {     //体验馆 cell类型
        _orgTitleLabel.text = @"体  验  馆:";
        _telephoneImageView.image = [UIImage imageNamed:@"experience_icon_synopsis_default"];
        _telephoneTitleLabel.text = @"简        介:";
    }
    
}


-(void)joinBtnClicked:(UIButton *)button{
    if (!jionBtnClickedEnable) {
        return;
    }
    if (self.joinedBlock) {
        
        NSInteger ID;
        //判断传机构id 还是体验馆id
        if (self.expericeModel !=nil) {
            ID = [self.expericeModel.expericeId integerValue];
        }else if(self.orgModel !=nil){
            ID = [self.orgModel.orgID integerValue];
        }
        self.joinedBlock(ID);
    }
}

-(void)settingBtnClicked{
    
    if (self.setDefaultBlock) {
        NSInteger ID;
        //判断传机构id 还是体验馆id
        if (self.expericeModel !=nil) {
            ID = [self.expericeModel.expericeId integerValue];
        }else if(self.orgModel !=nil){
            ID = [self.orgModel.orgID integerValue];
        }
        
        self.setDefaultBlock(ID);
    }
    
}

@end
